package exams;

/*
 *生成随机数在java中，
 */
import java.util.Scanner;

class NumRandom {
	public static void main(String args[]) { 
		
		while (1 > 0) {
			int guess=1, answer =1;  //reset every time
			System.out.print("请你猜下一个硬币的正反？1(为正)0(为反): ");
			Scanner sc = new Scanner(System.in);
				
			try{
				guess = sc.nextInt();
//				guess = Integer.parseInt(sc.next());
				
			}catch (Exception err){
				System.out.println("invalid input." );
				continue; 
			}
			
			double r = Math.random();
			if (r > 0.5) {
				System.out.print("硬币是正的, ");
			} else {
				System.out.print("硬币是反的, ");
				answer = 0;
			}
			//System.out.println("debug::::::::::: " + guess + " and " + answer + " test: " + (guess == answer) + " ran: " + r + ", " + (r>0.5));
			if (guess == answer)
				System.out.println("恭喜您选对了！:-)");
			else
				System.out.println("您运气不好！:-(");

			System.out.flush();
			System.out.println("continue?(Y/N) ");

			Scanner scGo = new Scanner(System.in);
			if (scGo.next().toUpperCase().equals("N")) {
				System.out.println("Thanks, game over.");
				return;
			} else {
				continue;
			}
		}
	}
}